<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_ctrl extends CI_Controller {

	function __construct() {
	
		parent::__construct ();
		$this->load->model('mdctype_model');
		$this->load->model('drugs_model');

	}

	function index() {
	
		$this->load->view('adminsite/home_view');
	}
	
	function inventory() {
	
		$data['drugs'] = $this->drugs_model->_getAll();
		$data['result'] = $this->drugs_model->select_all();
		
		$data['type'] = $this->mdctype_model->select_type();
		
		$this->load->view('adminsite/inv_view',$data);
	}
	
	function inventory2($data) {
	
		$data['drugs'] = $this->drugs_model->_getAll();
		$data['result'] = $this->drugs_model->select_all();
		
		$data['type'] = $this->mdctype_model->select_type();
		
		$this->load->view('adminsite/inv_search',$data);
	}
	
	function add_drug() {
	
		$data['mdc_name'] = $this->input->post('mdc_name');
		$data['mdctype_id'] = $this->input->post('mdc_type');
		$data['mdc_amount'] = $this->input->post('mdc_amount');
		$data['mdc_cost'] = $this->input->post('mdc_cost');
		
		$data['mdc_expire'] = $this->input->post('mdc_expire');
		$data['price1'] = $this->input->post('price1');
		$data['price2'] = $this->input->post('price2');
		$data['price3'] = $this->input->post('price3');
		
		$this->drugs_model->insert_mdc($data);
		
		redirect('inv_ctrl/inventory', 'refresh');	
	}
	
	public function search_keyword() { 
	
		$keyword = $this->input->post('keyword');
		
		$result = $this->drugs_model->search_key($keyword);		
		
			$data = array(
			'result' => $result
			);
			$this->load->view('adminsite/inv_search',$data);
			//$this->inventory2($data);
	}
	
	
	function delete()
	{
		$id = $this->uri->segment(3);
		$this->drugs_model->delete($id);
		
		$data['drugs'] = $this->drugs_model->_getAll();
		$data['result'] = $this->drugs_model->select_all();
		
		$data['type'] = $this->mdctype_model->select_type();
		$this->load->view('adminsite/inv_view',$data);
		
		redirect('inv_ctrl/inventory', 'refresh');
	}
}

	
